package main

import (
    "context"
    "github.com/grpc-ecosystem/grpc-gateway/runtime"
    "google.golang.org/grpc"
   // "gowork/gatewayGrpc/grpcServer/helper"
    "gowork/gatewayGrpc/grpcServer/services"
    "log"
    "net/http"
)

func main() {

    gwmux := runtime.NewServeMux()
    //opt := []grpc.DialOption{grpc.WithTransportCredentials(helper.GetClientCreds())}                           //由于是http访问grpc,所以http也相当于一个客户端，需要提供客户端秘钥才可以成功访问
    opt := []grpc.DialOption{grpc.WithInsecure()}
    err := services.RegisterProdServiceHandlerFromEndpoint(context.Background(), gwmux, "localhost:7429", opt) //localhost这是grpc的地址
    if err != nil {
        log.Fatal(err)
    }

    err = services.RegisterOrderServiceHandlerFromEndpoint(context.Background(), gwmux, "localhost:7429", opt) //localhost这是grpc的地址
    if err != nil {
        log.Fatal(err)
    }

    httpServer := &http.Server{
        Addr:    ":9302",
        Handler: gwmux,
    }
    httpServer.ListenAndServe()
    
}